package Test1;

import java.text.ParseException;
import java.util.*;

class ToStringTest {

    public static void main(String args[]) throws ParseException {

        HashMap<Student,String> m1 = new HashMap<>();
        TreeMap<Student,String> m = new TreeMap<>();
        Student s1 = new Student("wbk",20);
        Student s2 = new Student("zmh",19);
        Student s3 = new Student("theshy",20);
        Student s4 = new Student("theshy",20);


        m.put(s1,"hebei");
        m.put(s2,"henan");
        m.put(s3,"aaa");
        m.put(s4,"www");


        getnum(1,2,3,4,5);

        Collection<String> values = m.values();

//        m.put(s1,"hebei");
//        m.put(s2,"shijiazhuang");
//
//        extracted(m);
//
//        extracted1(m);
//
//        extracted2(m);





    }

    private static void getnum(int...arr) {

    }

    private static void extracted2(Map<Student, String> m) {
        m.forEach((Student s, String str)->{
            System.out.println(s+" "+str);
        });
    }

    private static void extracted1(Map<Student, String> m) {
        Set<Map.Entry<Student,String>> s = m.entrySet();

        for (Map.Entry<Student, String> e : s) {
            System.out.println(e.getKey()+"----"+e.getValue());
        }
    }

    private static void extracted(Map<Student, String> m) {
        Set<Student> s = m.keySet();

        for (Student student : s) {
            System.out.println(student+"----"+ m.get(student));

        }
    }


}

class Student implements Comparable<Student>{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (age != student.age) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }

    @Override
    public int compareTo(Student o) {
        int result = this.age-o.age;
        result = result ==0?this.getName().compareTo(o.getName()):result;
        return result;
    }
}

